package com.ruoyi.web.controller.applet.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.domain.SysAppClause;
import com.ruoyi.system.domain.SysAppPrescriptionInfo;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.dto.ClauseDicDataDTO;
import com.ruoyi.system.service.ISysAppClauseService;
import com.ruoyi.system.service.ISysAppPrescriptionInfoService;
import com.ruoyi.system.service.ISysDictTypeService;

@Controller
@RequestMapping("/applet/clause")
public class ClauseController {

	@Autowired
	private ISysDictTypeService dictTypeService;

	@Autowired
	private ISysAppPrescriptionInfoService sysAppPrescriptionInfoService;

	@Autowired
	private ISysAppClauseService sysAppClauseService;

	/**
	 * 获取条纹列表内容
	 * 
	 * @Description:
	 * @Author 豫东一棵草
	 * @DateTime 2020年10月18日 上午12:28:31
	 * @return
	 */
	@PostMapping("/selectClause")
	@ResponseBody
	public AjaxResult selectClause() {
		Map<String, Object> map = Maps.newConcurrentMap();
		List<SysDictData> dictDatas = dictTypeService.selectDictDataByType("sys_clause_class");
		ClauseDicDataDTO clauseDicDataDTO = null;
		List<ClauseDicDataDTO> sysAppClauses = Lists.newArrayList();
		for (SysDictData sysDictData : dictDatas) {
			clauseDicDataDTO = new ClauseDicDataDTO();
			BeanUtils.copyBeanProp(clauseDicDataDTO, sysDictData);

			SysAppClause appClause = new SysAppClause();
			appClause.setTypeId(sysDictData.getDictCode());
			List<SysAppClause> appClauses = sysAppClauseService.selectSysAppClauseList(appClause);
			clauseDicDataDTO.setClauseList(appClauses);
			sysAppClauses.add(clauseDicDataDTO);
		}
		map.put("sysAppClauses", sysAppClauses);
		return AjaxResult.success("操作成功", map);
	}

	@PostMapping("/selectClauseById")
	@ResponseBody
	public AjaxResult selectClauseById(Long id) {
		Map<String, Object> map = Maps.newConcurrentMap();

		/* 获取条纹详情 */
		SysAppClause sysAppClause = sysAppClauseService.selectSysAppClauseById(id);

		/* 获取条纹的方剂信息 */
		List<SysAppPrescriptionInfo> infos = sysAppPrescriptionInfoService.selectPrescriptionInfoListByClauseId(id);
		map.put("appClause", sysAppClause);
		map.put("infos", infos);
		return AjaxResult.success("操作成功", map);
	}

}
